不会对(*p)[5]赋初值了?

来源:百度知道 编辑:UC知道 时间:2024/06/21 14:23:09
#include "stdio.h"
void main()
{
char *s[3]={"asdf","ghjk","qwer"};
char (*p)[5];
*p=&s[0];
printf("%s\n",s[2]);
printf("%c\t%c\t\n",*(*p),*((*p)+1));
p++;
printf("%c\t%c\t\n",*(*p),*(p[0]+1));

}
这是一道填空题答案原题就是这我调试了下有错!

// 不明白的地方可以hi我
#include "stdio.h"
void main()
{
// char *s[3]={"asdf","ghjk","qwer"}; //要把字符串指针数组写为等价的二维字符数组,如下:
char s[3][5]= // 二维字符数组
{{'a','s','d','f','\0'},
{'g','h','j','k','\0'},
{'q','w','e','r','\0'}};
char (*p)[5] = s; // 指向(n×5)的二维字符数组指针,其中n可为任意,但5是固定的
printf("%s\n",s[2]);
printf("%c\t%c\t\n",*(*p),*((*p)+1));
p++;
printf("%c\t%c\t\n",*(*p),*(p[0]+1));

}

另外我又给你写了个示例,你可以拿去运行一下以加深理解:
#include<iostream>
using namespace std;
void main()
{
const int strLen = 6;
char (*p)[strLen]; // 为指向(n×strLen)的二维字符数组的指针,(n×strLen)的意义是
//此数组指针即可以指向有任意行,但只能有strLen列的二维字符数组
char ch_array1[2][strLen] =
{{'h',&